package controller.member;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractCommandController;
import org.springframework.web.servlet.mvc.Controller;

import Bean.memberBean;
import dao.memberDao;

public class pwFindController extends AbstractCommandController {
	private memberDao dao;
	public void setDao(memberDao dao){
		this.dao = dao;
	}

	@Override
	protected ModelAndView handle(HttpServletRequest arg0,
			HttpServletResponse arg1, Object arg2, BindException arg3)
			throws Exception {
	
		memberBean bean = (memberBean) arg2;

		ModelAndView mav = new ModelAndView();
		
		if(bean.getMid() == "" || bean.getMname() == "" || bean.getMssn1() == "" || bean.getMssn2() == ""){
			mav.setViewName("pwFind");
			return mav;
		}
		
		memberBean mBeanPw = dao.mFindPw(bean);
		
		if(mBeanPw == null){
			mav.setViewName("pwFind");
			return mav;
		}

		if(bean.getMid().equals(mBeanPw.getMid()) && bean.getMname().equals(mBeanPw.getMname()) && bean.getMssn1().equals(mBeanPw.getMssn1()) && bean.getMssn2().equals(mBeanPw.getMssn2())){
			mav.addObject("mBeanPw", mBeanPw);
			mav.setViewName("pwFind");
			return mav;
		}
		mav.setViewName("pwFind");
		return mav;
	}

}
